package offer;

public class offer_0016 {
    public double myPow(double x, int n) {
        if(n==0) return 1;
        if(n<0&&-1*n<0) return 1/(dp(x,-1*(n+1))*x);
        if(n<0) return 1/dp(x,-1*n);
        return dp(x,n);
    }
    public double dp(double x,int n){
        if(n==1) return x;
        double tmp=dp(x,n/2);
        if(n%2==1){
            return tmp*tmp*x;
        }
        else return tmp*tmp;
    }
}
